<?php

$func_name = "china_add_image.php";

if ('POST' == $_SERVER['REQUEST_METHOD']) {
    //Formulardaten erhalten
    log_message('[' . $func_name . ']' . POST_RECIVED);

    if (array_key_exists('obj_img', $_FILES)) {
        //var_dump($_FILES["obj_img"]);
        log_message('[' . $func_name . ']' . 'bla');
        $img_id = add_image($_FILES["obj_img"]);
        $img_size = getimagesize(get_image($img_id));
        log_message('[' . $func_name . '] ' . "Size: " . print_r($img_size, true));
        log_message('[' . $func_name . '] ' . "Chopping: $img_id");
        $img_id = chop_image($img_id, 1, 1, $img_size[0], $img_size[1]);
        log_message('[' . $func_name . '] ' . "New: $img_id");
        log_message('[' . $func_name . ']' . "Bild erhalten. ID: $img_id");
        unset($func_name);
        $to_tpl = array();
        $to_tpl["filename"] = 'output_json.tpl';
        $to_tpl["data"] = array();
        $to_tpl["data"]['image_id'] = $img_id;
        $to_tpl["data"]['image_url'] = get_image($img_id);
        return $to_tpl;
    }

    log_message('[' . $func_name . ']' . 'blubb');
}
log_message('[' . $func_name . ']' . "Keine Daten erhalten.");
unset($func_name);
$to_tpl = array();
$to_tpl["filename"] = 'output_json.tpl';
$to_tpl["data"] = array();
$to_tpl["data"]['image_id'] = IMAGE_NA_ID;
$to_tpl["data"]['image_url'] = get_image(IMAGE_NA_ID);
return $to_tpl;
?>